﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Interfleet.SE.UICompiler.Core.YahooCssCompressor
{
    /// <summary>
    /// Argument builder for the Yahoo UI Compressor Css.
    /// </summary>
    public class YCArgumentBuilder : ArgumentBuilder
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="arguments"><see cref="Arguments"/> for the compilation</param>
        public YCArgumentBuilder(Arguments arguments)
            : this(arguments, new FileProvider())
        { }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="arguments"><see cref="Arguments"/> for the compilation</param>
        /// <param name="fileInfoProvider">An instance of <see cref="IFileProvider"/></param>
        public YCArgumentBuilder(Arguments arguments, IFileProvider fileInfoProvider)
            : base(arguments, fileInfoProvider, new YCCompileOptions())
        {

        }

        /// <summary>
        /// Reads the content of the files specified in the Arguments and
        /// returns the concatenated result.
        /// </summary>
        /// <returns>File content of the files</returns>
        /// <seealso cref="Arguments"/>
        public override string Build()
        {
            var sb = new StringBuilder();
            foreach (var file in Arguments.Files)
            {
                sb.Append(FileProvider.ReadFileToEnd(file));
            }
            return sb.ToString();
        }
    }
}
